<template>
  <div class="configDetail">
    <van-nav-bar
      :title="$route.meta.title"
      left-arrow
      :border="false"
      @click-left="clickLeft"
      
      class="nav-bar">
      <template #right>
        <van-icon name="success" size="20" @click="clickRight" /><span
          style="color: #fff; font-size: 20px"
          >递交</span
        >
      </template>
    </van-nav-bar>

    <div class="content">
      <div
        style="
          display: flex;
          justify-content: space-between;
          align-items: center;
        ">
        <van-tag plain type="primary" style="margin: 10px 10px 10px 20px"
          >基本信息</van-tag
        >
      </div>
      <van-row gutter="20" type="flex" align="center">
        <van-col span="12">
          <van-field
            v-model="checkType"
            name="checkType"
            label="检验类型"
            input-align="center"
            left-icon="scan"
            @click-left-icon="openScan()"
            class="deviceStyle">
            <template #input>
              <fixed-select v-model="checkType" :dataList="checkTypeArr" />
            </template>
          </van-field>
        </van-col>
        <van-col span="12">
          <van-field
            readonly
            clickable
            label="检验信息"
            v-model="sampleName"
            placeholder="请选择"
            input-align="center"
            @click="showSamplePicker = true"
            class="select-record" />
        </van-col>
        <van-col span="12" class="readonly">
          <van-field
            readonly
            clickable
            label="批号标准"
            v-model="totalText"
            input-align="center" />
        </van-col>
        <van-col
          span="12"
          style="display: flex; align-items: center; justify-content: flex-end">
          <van-button
            size="mini"
            type="info"
            style="margin-right: 20px; padding: 0px 20px"
            @click="confirmReceipt()"
            v-if="showCon"
            >样品接收</van-button
          >
          <van-button
            size="mini"
            type="info"
            style="margin-right: 20px; padding: 0px 20px"
						v-if="!showCon"
            @click="fillValue()"
            >一键赋值</van-button
          >
          <van-button
            size="mini"
            type="info"
						v-if="!showCon"
            style="margin-right: 25px; padding: 0px 20px"
            @click="jumpToRecord()"
            >检验记录</van-button
          >
        </van-col>
      </van-row>
      <div
        style="display: flex; justify-content: space-between; margin-top: 20px">
        <van-tag plain type="primary" style="margin: 10px 10px 10px 20px"
          >检验列表</van-tag
        >
      </div>
      <div class="list-style">
        <van-list
          :immediate-check="false"
          :offset="1"
          v-for="(v, i) in list"
          :key="i"
          type="flex">
          <van-cell
            :title="v.attributeName"
            title-class="custom-title"
            value-class="custom-value"
            label-class="custom-label">
            <template #label>
              <div
                style="
                  display: flex;
                  height: 50px;
                  align-items: center;
                  margin-bottom: 10px;
                "
                v-if="v.dataType == 'Varchar'">
                检验结果：
                <van-field
                  v-model="v.attributeValue"
                  name="attributeValue"
                  readonly
                  placeholder="请选择"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @click="
                    {
                      varcharShow = true;
                      type = v.dataType;
                      attributeCode = v.attributeCode;
                    }
                  ">
                </van-field>
              </div>
              <div
                style="
                  display: flex;
                  height: 50px;
                  align-items: center;
                  margin-bottom: 10px;
                "
                v-if="v.dataType == '字符型'">
                检验结果：
                <van-field
                  v-model="v.attributeValue"
                  name="attributeValue"
                  readonly
                  placeholder="请选择"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @click="
                    {
                      varcharShow = true;
                      type = v.dataType;
                      attributeCode = v.attributeCode;
                    }
                  ">
                </van-field>
              </div>
              <div
                style="
                  display: flex;
                  height: 50px;
                  align-items: center;
                  margin-bottom: 10px;
                "
                v-if="v.dataType == 'Bool'">
                检验结果：
                <van-field
                  v-model="boolText"
                  name="attributeValue"
                  readonly
                  placeholder="请选择"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @click="
                    {
                      boolShow = true;
                      type = v.dataType;
                      attributeCode = v.attributeCode;
                    }
                  ">
                </van-field>
              </div>

              <div
                style="
                  display: flex;
                  height: 50px;
                  align-items: center;
                  margin-bottom: 10px;
                "
                v-if="v.dataType == 'Date'">
                检验结果：
                <van-field
                  v-model="v.attributeValue"
                  name="attributeValue"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @focus="
                    type = v.dataType;
                    attributeCode = v.attributeCode;
                  "
                  @input="dateChange">
                </van-field>
              </div>

              <div
                style="
                  display: flex;
                  height: 50px;
                  align-items: center;
                  margin-bottom: 10px;
                "
                v-if="v.dataType == 'Float' && v.attributeList == null">
                检验结果：
                <van-field
                  v-model="v.floatType"
                  name="attributeValue"
                  readonly
                  placeholder="请选择"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @click="
                    {
                      floatShow = true;
                      type = v.dataType;
                      hasMore = false;
                      attributeCode = v.attributeCode;
                    }
                  ">
                </van-field>
                <van-field
                  v-model="v.floatValue"
                  name="attributeValue"
                  input-align="center"
                  style="
                    height: 50px;
                    width: 300px;
                    box-sizing: border-box;
                    padding: 0;
                    margin-right: 10px;
                  "
                  @focus="
                    type = v.dataType;
                    attributeCode = v.attributeCode;
                    standards = v.standards;
                    hasMore = false;
                  "
                  @input="floatChange">
                </van-field>
              </div>

              <div
                v-if="
                  v.dataType == 'Float' &&
                  v.attributeList &&
                  v.attributeList.length > 0
                ">
                检验结果：
                <van-list v-for="(t, j) in v.attributeList" :key="j">
                  <div
                    style="display: flex; margin: 10px 0; padding-left: 70px">
                    <van-field
                      v-model="t.floatType"
                      name="attributeValue"
                      readonly
                      placeholder="请选择"
                      input-align="center"
                      style="
                        height: 50px;
                        width: 300px;
                        box-sizing: border-box;
                        padding: 0;
                        margin-right: 35px;
                      "
                      @click="
                        {
                          floatShow = true;
                          type = v.dataType;
                          hasMore = true;
                          moreAutoId = t.iautoid;
                          attributeCode = v.attributeCode;
                        }
                      ">
                    </van-field>
                    <van-field
                      v-model="t.floatValue"
                      name="attributeValue"
                      input-align="center"
                      style="
                        height: 50px;
                        width: 300px;
                        box-sizing: border-box;
                        padding: 0;
                      "
                      @focus="
                        type = v.dataType;
                        attributeCode = v.attributeCode;
                        standards = v.standards;
                        hasMore = true;
                        moreAutoId = t.iautoid;
                      "
                      @input="floatChange">
                    </van-field>
                  </div>
                </van-list>
              </div>

              <div style="color: red" v-if="v.state == 1">
                检验标准：{{ v.attributeStandard }}
              </div>
              <div v-else>检验标准：{{ v.attributeStandard }}</div>
            </template>
          </van-cell>
        </van-list>
      </div>
    </div>

    <van-popup
      v-model="showSamplePicker"
      position="bottom"
      round
      :style="{ height: '70%' }"
      :lock-scroll="false">
      <van-cascader
        v-model="sampleValue"
        :options="sampleArr"
        @close="showSamplePicker = false"
        @finish="onSampleFinish"
        :field-names="sampleNames">
        <template #title>
          <van-row
            gutter="20"
            type="flex"
            align="center"
            style="padding-top: 10px">
            <van-col span="10">
              <van-field
                v-model="startTime"
                name="startTime"
                label="开始日期"
                input-align="center"
                class="deviceStyle">
                <template #input>
                  <picker-date v-model="startTime" timeType="date" />
                </template>
              </van-field>
            </van-col>
            <van-col span="10">
              <van-field
                readonly
                clickable
                label="结束日期"
                v-model="endTime"
                placeholder="请选择"
                input-align="center"
                class="select-record">
                <template #input>
                  <picker-date v-model="endTime" timeType="date" />
                </template>
              </van-field>
            </van-col>
            <van-col span="4">
              <van-button
                type="default"
                size="small"
                style="margin-right: 10px"
                @click="handelReset()">
                重置</van-button
              >
              <van-button type="primary" size="small" @click="handleSearch"
                >查询</van-button
              >
            </van-col>
          </van-row>
        </template>
      </van-cascader>
    </van-popup>
    <van-popup v-model="showPicker" round position="bottom">
      <van-picker
        show-toolbar
        :columns="userList"
        @cancel="showPicker = false"
        @confirm="onConfirm" />
    </van-popup>
    <van-popup
      v-model="varcharShow"
      safe-area-inset-bottom
      close-on-popstate
      position="bottom"
      get-container="body"
      :style="{ height: '50%' }"
      round>
      <div class="search-wapper">
        <van-search
          v-model="varcharValue"
          placeholder="请输入关键词"
          @input="debouncedInput" />

        <van-cell v-if="searchList.length < 1">暂无匹配项</van-cell>

        <van-cell-group v-else>
          <van-cell
            v-for="item in searchList"
            :key="item"
            :title="item"
            @click="handleCellClick(item)" />
        </van-cell-group>
      </div>
    </van-popup>

    <van-popup v-model="boolShow" round position="bottom">
      <van-picker
        show-toolbar
        :columns="boolList"
        @cancel="boolShow = false"
        @confirm="onBoolConfirm" />
    </van-popup>

    <van-popup v-model="floatShow" round position="bottom">
      <van-picker
        show-toolbar
        :columns="floatList"
        @cancel="floatShow = false"
        @confirm="onFloatConfirm" />
    </van-popup>
    <div class="scan" v-if="scanShow">
      <div id="bcid">
        <div style="height: 40%"></div>
        <p class="tip">...载入中...</p>
      </div>
      <footer>
        <button @click="closeModel">退出</button>
      </footer>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import { GetTestShareTreeByCode, getTestTree } from "@/api/base";
import {
  CommonPrintDownLoad,
  GetDictionarySelect,
  getMaterialReportData,
  GetPrintDownLoadByIautoid,
  getTestAttributes,
  GetTestDate,
  saveUserTestAttributes,
} from "@/api/check";
import FixedSelect from "@/components/FixedSelect";
import MultSelect from "@/components/MultSelect";
import PickerDate from "@/components/PickerDate";
import SelectTwo from "@/components/SelectTwo";
import { to } from "@/utils";
import {
  Button,
  Calendar,
  cascader,
  Cell,
  CellGroup,
  Col,
  Dialog,
  Field,
  Icon,
  List,
  NavBar,
  Notify,
  Picker,
  Popup,
  Row,
  Search,
  Tag,
  Uploader,
} from "vant";
let scan = null;
export default {
  name: "myCheckObject",
  components: {
    PickerDate,
    [NavBar.name]: NavBar,
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Button.name]: Button,
    [Popup.name]: Popup,
    [Field.name]: Field,
    [Calendar.name]: Calendar,
    [Notify.name]: Notify,
    [Uploader.name]: Uploader,
    [List.name]: List,
    [Tag.name]: Tag,
    [Picker.name]: Picker,
    [Dialog.name]: Dialog,
    [Search.name]: Search,
    [cascader.name]: cascader,
    [Col.name]: Col,
    [Row.name]: Row,
    MultSelect,
    SelectTwo,
    FixedSelect,
  },
  data() {
    return {
      token: "",
      checkType: "1", //检验类型
      checkTypeArr: [
        { value: 1, text: "样品检验" },
        { value: 2, text: "稳定性检验" },
      ],
      startTime: "",
      endTime: "",
      sampleName: "", //合并后检验样品
      showSamplePicker: false,
      sampleArr: [],
      sampleValue: "",
      sampleNames: {
        text: "name",
        value: "code",
      },
      totalText: "", //标准批号
      loading: false,
      finished: false,
      list: [],
      userCode: "",
      userName: "",
      showPicker: false,
      userList: [],
      attributeValue: "",
      varcharShow: false,
      searchList: [],
      varcharValue: "",
      type: "",
      attributeCode: "",
      debouncedInput: null,
      boolShow: false,
      boolText: "",
      boolList: [
        { id: 1, text: "是" },
        { id: 2, text: "否" },
      ],
      floatShow: false,
      floatList: ["=", "未检出", "<", "≤", ">", "≥"],
      hasMore: false,
      floatChange: null,
      floatValue: "",
      moreAutoId: "",
      materialCode: "",
      testID: "",
      batchID: "",
      treeNode: "",
      showCon: false,
      searchData: "",
      scanShow: false,
      scanType: "",
      scanObj: {},
      timer: null,
      standards: [],
			batchList: [],
    };
  },
  watch: {
    checkType(val) {
      if (val) {
        this.token = localStorage.getItem("tokenKey");
        this.getSampleData();
      }
    },
  },
  activated() {
    this.token = localStorage.getItem("tokenKey");
    this.getSampleData();
    this.fetchSearchList();
    this.debouncedInput = this.debounce(this.getValue);
    this.floatChange = this.debounce(this.getFloatValue);
		console.log(this.$route.params)
		if(this.$route.params.treeNode&&JSON.parse(this.$route.params.treeNode)){
			this.treeNode = JSON.parse(this.$route.params.treeNode)
			this.sampleName = this.treeNode.name;
			this.sampleValue = this.treeNode.code;
      this.batchID = this.treeNode.batchID;
      this.testID = this.treeNode.code;
      this.materialCode = this.treeNode.materialCode;
      this.totalText =
			this.treeNode.batchID +
        " " +
        this.treeNode.materialName +
        " " +
        "(" +
        this.treeNode.standardBaseOn +
        ")";
      this.getListValue();
		}
  },
  unmounted() {
    console.log('sdfsdfsf')
  },
  methods: {
    handelReset(){
      this.startTime = ''
      this.endTime = ''
      this.getSampleData()
    },
    handleSearch(){
      let timeStempStart = ''
      let timeStempEnd = ''
      if(this.endTime&&!this.startTime) return this.$toast('请选择开始日期')
      if (this.startTime) {
        timeStempStart = new Date(this.startTime).getTime()
      }
      if (this.endTime) {
        timeStempEnd = new Date(this.endTime).getTime()
      }
      if(timeStempStart&&timeStempEnd){
        if(timeStempStart>timeStempEnd) return this.$toast('开始日期不能大于结束日期')
      }
      this.getSampleData()
      // this.sampleArr = []
    },
    getListValue() {
      var params = {
        testID: this.treeNode.code,
        materialCode: this.treeNode.materialCode,
        batchID: this.treeNode.batchID,
        Token: this.token,
      };
      GetTestDate(params)
        .then((response) => {
          var res = response.Result;
          this.searchData = res;
          this.GetPrintDownLoadByIautoid(res.iautoid);
        })
        .catch(() => {});
    },
    GetPrintDownLoadByIautoid(iautoid) {
      var params = {
        iautoid: iautoid,
        Module: "4",
        Token: this.token,
      };
      GetPrintDownLoadByIautoid(params)
        .then((response) => {
          if (response.Result == "1") {
            this.showCon = false;
            this.getItemList(this.treeNode.code, this.treeNode.materialCode);
          } else {
            this.showCon = true;
            Notify({ type: "warning", message: "请先确认接受样品" });
          }
        })
        .catch(() => {});
    },
    confirmReceipt() {
      var params = {
        iautoid: this.searchData.iautoid,
        Module: "4",
        Token: this.token,
      };
      CommonPrintDownLoad(params)
        .then((response) => {
          this.getListValue();
        })
        .catch(() => {});
    },
    jumpToRecord() {
      if (
        this.treeNode == "" ||
        this.treeNode == undefined ||
        this.treeNode == null
      ) {
        Notify({ type: "warning", message: "请选择要检验的样品" });
        return false;
      }
      var paramData = JSON.stringify(this.treeNode);
			
      this.$router.push({
        name: "configDetail",
        params: {
					batchList: JSON.stringify(this.batchList),
          paramData: paramData,
        },
      });
    },
    clickLeft() {
      if (scan && scan != "") {
        scan.close();
      }
      this.$router.replace({ name: "home" });
    },

    clickRight() {
      var subDataArr = [];
      this.list.map((item) => {
        var attributeList = item.attributeList;
        if (attributeList && attributeList.length > 0) {
          attributeList.map((item1) => {
            if (item1.dataType == "Float") {
              item1.attributeValue = item1.floatValue;
            }
          });
        }
        var subObj = {
          attributeCode: item.attributeCode,
          materialCode: item.materialCode,
          testID: item.testID,
          attributeList: attributeList,
        };
        if (item.dataType == "Float") {
          subObj.attributeValue = item.floatValue;
        } else {
          subObj.attributeValue = item.attributeValue;
        }
        subDataArr.push(subObj);
      });
      var queryParams = {
        number: "40",
        testID: this.testID,
        materialCode: this.materialCode,
        attributes: subDataArr,
        Token: this.token,
      };
      saveUserTestAttributes(queryParams)
        .then((response) => {
          Notify({ type: "success", message: response.ErrorMsg });
          this.getItemList(this.testID, this.materialCode);
        })
        .catch(() => {});
    },
    async getSampleData() {
      var that = this;
      console.log('this.token',this.token)
      // if(!this.token) return
      let loading = this.$toast({
        type: 'loading',
        duration: 0
      })

      var queryParams = {
        pageModel: {
          Token: this.token,
          Search: ["30", "UrgencyDegree"],
          Type: this.checkType,
          StartTime: this.startTime||undefined,
          EndTime: this.endTime||undefined,
        },
      };
      const [err, res] = await to(getTestTree(queryParams));
      loading.close()
      if (err) return;
      var result = res.Result;
      this.dowhile(result);
			this.formatTreeData(result);
      this.sampleArr = result;
			console.log('this.sampleArr',this.sampleArr)
    },

		// 利用该方法将tree数据的父级保存到子级数据中
		formatTreeData(arr, level = 1, objArr = []) {
			arr.forEach(e => {
				e.treeLevel = level;
				if(e.shareDate) e.name = `(${e.shareDate})${e.name} `;
				objArr.forEach((ancestor, index) => {
					e[`level${index}`] = ancestor;
				});
				if (e.children && e.children.length > 0) {
					const newAncestors = [...objArr, {name:e.name,code:e.code}]; 
					this.formatTreeData(e.children, level + 1, newAncestors);
				}
			});
		},
    dowhile(b) {
      for (var i = 0; i < b.length; i++) {
        if (b[i].children && b[i].children.length > 0) {
          this.dowhile(b[i].children);
        } else {
          delete b[i].children;
        }
      }
    },
    onSampleFinish({ selectedOptions }) {
      this.showSamplePicker = false;
      var len = selectedOptions.length;
      var toDetail = selectedOptions[len - 1];
			this.batchList = selectedOptions[len - 2].children;
      this.treeNode = toDetail;
      this.sampleName = toDetail.name;
      this.batchID = toDetail.batchID;
      this.testID = toDetail.code;
      this.materialCode = toDetail.materialCode;
      this.totalText =
        toDetail.batchID +
        " " +
        toDetail.materialName +
        " " +
        "(" +
        toDetail.standardBaseOn +
        ")";
			console.log(this.sampleValue)
      this.getListValue();
    },
    getItemList(code, materialCode) {
      var queryParams = { Token: this.token, Search: [code, "40"] };
      getTestAttributes(queryParams)
        .then((response) => {
          var result = response.Result;
          if (result.length == 0) {
            // this.getSampleData();
            // this.sampleName = "";
						return
          }
          for (var i = 0; i < result.length; i++) {
            result[i].materialCode = materialCode;
            result[i].state = 0;
            if (result[i].dataType == "Float") {
              result[i].floatType = "=";
              result[i].floatValue = "";
            }
          }
          this.list = result;
        })
        .catch(() => {});
    },
    onConfirm() {},
    async fetchSearchList() {
      // if(!this.token) return
      console.log(this.token)
      const queryParams = {
        pageModel: {
          Token: this.token,
          Search: ["CheckMessage"],
        },
      };
      const [err, res] = await to(GetDictionarySelect(queryParams));
      if (err) return [];
      var result = res.Result;
      var spec = [];
      result.map((item) => {
        spec.push(item.text);
      });
      this.searchList = spec;
    },
    async fillValue() {
			if(!this.list.length) return Notify({ type: "warning",message: "暂无可赋值的项目"});
      var params = {
        Token: this.token,
        batchID: this.batchID,
        testID: this.testID,
        materialCode: this.materialCode,
      };
      const [err, res] = await to(getMaterialReportData(params));
      if (err) return [];
      var result = res.Result.data;
      if (result && result.length > 0) {
        result.map((item) => {
          var val = item.attributeValue;
          this.list.map((item1) => {
            if (item.attributeCode == item1.attributeCode) {
              if (item1.dataType != "Date" && item1.dataType != "Bool") {
                // var res = item1.standards;
                // var symbol = res.companyDataType;
                // var symrebol = res.compareType;
                // var symrulebol = res.ruleDataType;
                // var ruleLowLine = res.ruleLowLine;
                // var ruleUpLine = res.ruleUpLine;
                // var companyLowLine = res.companyLowLine;
                // var companyUpLine = res.companyUpLine;
                // var confirmText = "值不符合规定";
                // var showBox = false;
                // if (symbol == "GT" || symrulebol == "GT" || symrebol == "GT") {
                //   //大于
                //   if (ruleLowLine != "") {
                //     if (Number(val) <= Number(ruleLowLine)) {
                //       showBox = true;
                //       confirmText += ",法规下限" + ruleLowLine;
                //     }
                //   }
                //   if (companyLowLine != "") {
                //     if (Number(val) <= Number(companyLowLine)) {
                //       showBox = true;
                //       confirmText += ",自控下限" + companyLowLine;
                //     }
                //   }
                // } else if (
                //   symbol == "LT" ||
                //   symrulebol == "LT" ||
                //   symrebol == "LT"
                // ) {
                //   //小于
                //   if (ruleUpLine != "") {
                //     if (Number(val) >= Number(ruleUpLine)) {
                //       showBox = true;
                //       confirmText += ",法规上限" + ruleUpLine;
                //     }
                //   }
                //   if (companyUpLine != "") {
                //     if (Number(val) >= Number(companyUpLine)) {
                //       showBox = true;
                //       confirmText += ",自控上限" + companyUpLine;
                //     }
                //   }
                // } else if (
                //   symbol == "E" ||
                //   symrulebol == "E" ||
                //   symrebol == "E"
                // ) {
                //   //等于
                //   if (val == res.standardString) {
                //     $(this).next("span").hide();
                //   } else {
                //     showBox = true;
                //     confirmText = "值不符合规定,值为:" + res.standardString;
                //   }
                // } else if (
                //   symbol == "NE" ||
                //   symrulebol == "NE" ||
                //   symrebol == "NE"
                // ) {
                //   //不等于
                //   if (val != res.standardString) {
                //     $(this).next("span").hide();
                //   } else {
                //     showBox = true;
                //     confirmText = "值不符合规定,值为:" + res.standardString;
                //   }
                // } else if (
                //   symbol == "D" ||
                //   symrulebol == "D" ||
                //   symrebol == "D"
                // ) {
                //   //区间值
                //   if (ruleLowLine != "") {
                //     if (Number(val) < Number(ruleLowLine)) {
                //       showBox = true;
                //       confirmText += ",法规下限" + ruleLowLine;
                //     }
                //   }
                //   if (companyLowLine != "") {
                //     if (Number(val) < Number(companyLowLine)) {
                //       showBox = true;
                //       confirmText += ",自控下限" + companyLowLine;
                //     }
                //   }
                //   if (ruleUpLine != "") {
                //     if (Number(val) > Number(ruleUpLine)) {
                //       showBox = true;
                //       confirmText += ",法规上限" + ruleUpLine;
                //     }
                //   }
                //   if (companyUpLine != "") {
                //     if (Number(val) > Number(companyUpLine)) {
                //       showBox = true;
                //       confirmText += ",自控上限" + companyUpLine;
                //     }
                //   }
                // } else if (
                //   symbol == "GTE" ||
                //   symrulebol == "GTE" ||
                //   symrebol == "GTE"
                // ) {
                //   //大于等于
                //   if (ruleLowLine != "") {
                //     if (Number(val) < Number(ruleLowLine)) {
                //       showBox = true;
                //       confirmText += ",法规下限" + ruleLowLine;
                //     }
                //   }
                //   if (companyLowLine != "") {
                //     if (Number(val) < Number(companyLowLine)) {
                //       showBox = true;
                //       confirmText += ",自控下限" + companyLowLine;
                //     }
                //   }
                // } else if (
                //   symbol == "LTE" ||
                //   symrulebol == "LTE" ||
                //   symrebol == "LTE"
                // ) {
                //   //小于等于
                //   if (ruleUpLine != "") {
                //     if (Number(val) > Number(ruleUpLine)) {
                //       showBox = true;
                //       confirmText += ",法规上限" + ruleUpLine;
                //     }
                //   }
                //   if (companyUpLine != "") {
                //     if (Number(val) > Number(companyUpLine)) {
                //       showBox = true;
                //       confirmText += ",自控上限" + companyUpLine;
                //     }
                //   }
                // }

                if (item1.dataType == "Float") {
                  // if (showBox) {
                  //   item1.state = 1;
                  // }
                  // 是数字再赋值
                  if(!isNaN(Number(item.attributeValue))) item1.floatValue = item.attributeValue;
                  if(item.attributeValue === '/') item1.floatValue = item.attributeValue;

                } else {
                  item1.attributeValue = item.attributeValue;
                }
              }
            }
          });
        });
      }
    },
    handleCellClick(value) {
      this.varcharValue = value;
      for (var i = 0; i < this.list.length; i++) {
        var el = this.list[i];
        if (this.type == "Varchar" || this.type == "字符型") {
          if (el.attributeCode == this.attributeCode) {
            el.attributeValue = value;
            this.varcharShow = false;
            return;
          }
        }
      }
    },
    debounce(fn) {
      var that = this;
      var timer = null;
      return function () {
        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(() => {
          fn();
          timer = null;
        }, 500);
      };
    },
    getValue() {
      for (var i = 0; i < this.list.length; i++) {
        var el = this.list[i];
        if (this.type == "Varchar" || this.type == "字符型") {
          if (el.attributeCode == this.attributeCode) {
            el.attributeValue = this.varcharValue;
            return;
          }
        }
      }
    },
    onClose() {
      this.varcharShow = false;
    },
    onBoolConfirm(value) {
      var boolValue = value.id;
      this.boolText = value.text;
      for (var i = 0; i < this.list.length; i++) {
        var el = this.list[i];
        if (this.type == "Bool" && el.attributeCode == this.attributeCode) {
          el.attributeValue = boolValue;
          this.showPicker = false;
          return;
        }
      }
    },
    onFloatConfirm(value) {
      if (!this.hasMore) {
        for (var i = 0; i < this.list.length; i++) {
          var el = this.list[i];
          if (this.type == "Float" && el.attributeCode == this.attributeCode) {
            el.floatType = value;
            if (el.floatValue) {
              if (value != "=" && value != "未检出") {
                el.attributeValue = value + el.floatValue;
              } else if (value == "未检出") {
                el.attributeValue = value;
              } else {
                el.attributeValue = el.floatValue;
              }
            }
            this.floatShow = false;
            return;
          }
        }
      } else {
        for (var i = 0; i < this.list.length; i++) {
          var el = this.list[i];
          if (this.type == "Float" && el.attributeCode == this.attributeCode) {
            var attr = el.attributeList;
            for (var j = 0; j < attr.length; j++) {
              if (this.moreAutoId == attr[j].iautoid) {
                attr[j].floatType = value;
                if (attr[j].floatValue) {
                  if (value != "=" && value != "未检出") {
                    attr[j].attributeValue = value + attr[j].floatValue;
                  } else if (value == "未检出") {
                    el.attributeValue = value;
                  } else {
                    attr[j].attributeValue = attr[j].floatValue;
                  }
                }
                this.floatShow = false;
                return;
              }
            }
          }
        }
      }
    },
    getFloatValue() {
      if (!this.hasMore) {
        for (var i = 0; i < this.list.length; i++) {
          var el = this.list[i];
          if (this.type == "Float" && el.attributeCode == this.attributeCode) {
            if (el.floatType) {
              if (el.floatType != "=" && el.floatType != "未检出") {
                el.attributeValue = el.floatType + el.floatValue;
                this.ifOutStandards(el.floatValue);
              } else if (el.floatType == "未检出") {
                el.attributeValue = el.floatType;
              } else {
                el.attributeValue = el.floatValue;
                this.ifOutStandards(el.floatValue);
              }
            }
            return;
          }
        }
      } else {
        for (var i = 0; i < this.list.length; i++) {
          var el = this.list[i];
          if (this.type == "Float" && el.attributeCode == this.attributeCode) {
            var attr = el.attributeList;
            for (var j = 0; j < attr.length; j++) {
              if (this.moreAutoId == attr[j].iautoid) {
                if (attr[j].floatType) {
                  if (
                    attr[j].floatType != "=" &&
                    attr[j].floatType != "未检出"
                  ) {
                    attr[j].attributeValue =
                      attr[j].floatType + attr[j].floatValue;
                    this.ifOutStandards(attr[j].floatValue);
                  } else if (attr[j].floatType == "未检出") {
                    el.attributeValue = attr[j].floatType;
                  } else {
                    attr[j].attributeValue = attr[j].floatValue;
                    this.ifOutStandards(attr[j].floatValue);
                  }
                }
                return;
              }
            }
          }
        }
      }
    },
    ifOutStandards(val) {
      var symbol = this.standards.companyDataType;
      var symrebol = this.standards.compareType;
      var symrulebol = this.standards.ruleDataType;
      var ruleLowLine = this.standards.ruleLowLine;
      var ruleUpLine = this.standards.ruleUpLine;
      var companyLowLine = this.standards.companyLowLine;
      var companyUpLine = this.standards.companyUpLine;
      var confirmText = "值不符合规定";
      var showBox = false;
      if (symbol == "GT" || symrulebol == "GT" || symrebol == "GT") {
        //大于
        if (ruleLowLine != "") {
          if (Number(val) <= Number(ruleLowLine)) {
            showBox = true;
            confirmText += ",法规下限" + ruleLowLine;
          }
        }
        if (companyLowLine != "") {
          if (Number(val) <= Number(companyLowLine)) {
            showBox = true;
            confirmText += ",自控下限" + companyLowLine;
          }
        }
      } else if (symbol == "LT" || symrulebol == "LT" || symrebol == "LT") {
        //小于
        if (ruleUpLine != "") {
          if (Number(val) >= Number(ruleUpLine)) {
            showBox = true;
            confirmText += ",法规上限" + ruleUpLine;
          }
        }
        if (companyUpLine != "") {
          if (Number(val) >= Number(companyUpLine)) {
            showBox = true;
            confirmText += ",自控上限" + companyUpLine;
          }
        }
      } else if (symbol == "E" || symrulebol == "E" || symrebol == "E") {
        //等于
        if (val == res.standardString) {
          $(this).next("span").hide();
        } else {
          showBox = true;
          confirmText = "值不符合规定,值为:" + res.standardString;
        }
      } else if (symbol == "NE" || symrulebol == "NE" || symrebol == "NE") {
        //不等于
        if (val != res.standardString) {
          $(this).next("span").hide();
        } else {
          showBox = true;
          confirmText = "值不符合规定,值为:" + res.standardString;
        }
      } else if (symbol == "D" || symrulebol == "D" || symrebol == "D") {
        //区间值
        if (ruleLowLine != "") {
          if (Number(val) < Number(ruleLowLine)) {
            showBox = true;
            confirmText += ",法规下限" + ruleLowLine;
          }
        }
        if (companyLowLine != "") {
          if (Number(val) < Number(companyLowLine)) {
            showBox = true;
            confirmText += ",自控下限" + companyLowLine;
          }
        }
        if (ruleUpLine != "") {
          if (Number(val) > Number(ruleUpLine)) {
            showBox = true;
            confirmText += ",法规上限" + ruleUpLine;
          }
        }
        if (companyUpLine != "") {
          if (Number(val) > Number(companyUpLine)) {
            showBox = true;
            confirmText += ",自控上限" + companyUpLine;
          }
        }
      } else if (symbol == "GTE" || symrulebol == "GTE" || symrebol == "GTE") {
        //大于等于
        if (ruleLowLine != "") {
          if (Number(val) < Number(ruleLowLine)) {
            showBox = true;
            confirmText += ",法规下限" + ruleLowLine;
          }
        }
        if (companyLowLine != "") {
          if (Number(val) < Number(companyLowLine)) {
            showBox = true;
            confirmText += ",自控下限" + companyLowLine;
          }
        }
      } else if (symbol == "LTE" || symrulebol == "LTE" || symrebol == "LTE") {
        //小于等于
        if (ruleUpLine != "") {
          if (Number(val) > Number(ruleUpLine)) {
            showBox = true;
            confirmText += ",法规上限" + ruleUpLine;
          }
        }
        if (companyUpLine != "") {
          if (Number(val) > Number(companyUpLine)) {
            showBox = true;
            confirmText += ",自控上限" + companyUpLine;
          }
        }
      }

      if (showBox) {
        Notify({ type: "warning", message: confirmText });
      }
    },
    openScan() {
      var that = this;
      this.scanShow = true;
      this.timer = setTimeout(that.startRecognize, 500);
    },
    startRecognize() {
      var that = this;
      this.timer = null;
      if (!window.plus) return;
      scan = new plus.barcode.Barcode("bcid");
      scan.onmarked = onmarked;
      scan.start();
      function onmarked(type, result, file) {
        switch (type) {
          case plus.barcode.QR:
            type = "QR";
            break;
          case plus.barcode.EAN13:
            type = "EAN13";
            break;
          case plus.barcode.EAN8:
            type = "EAN8";
            break;
          default:
            type = "其它" + type;
            break;
        }
        scan.close();
        that.scanShow = false;
        console.log(result);
        that.getScanType(JSON.parse(result).testID);
      }
    },
    closeModel() {
      this.scanShow = false;
      if (!window.plus) return;
      scan.close();
    },
    async getScanType(id) {
      var params = {
        TestId: id,
        Token: this.token,
      };
      const [err, res] = await to(GetTestShareTreeByCode(params));
      this.treeNode = res.Result;

      this.sampleName = this.treeNode.name;
      this.batchID = this.treeNode.batchID;
      this.testID = this.treeNode.code;
      this.materialCode = this.treeNode.materialCode;
      this.totalText =
        this.treeNode.batchID +
        " " +
        this.treeNode.materialName +
        " " +
        "(" +
        this.treeNode.standardBaseOn +
        ")";

      this.getListValue();
    },
  },
};
</script>
<style></style>
<style scoped lang="less">
input[name="attributeValue"] {
  /* border: 1px solid #ebedf0; */
  height: 0.6rem;
  box-sizing: border-box;
}
.list-style /deep/.van-field__body {
  border: 1px solid #ccc;
}
.configDetail {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-y: hidden;
  // color: #fff;
}
.content {
  height: calc(100% - 1rem);
  overflow: auto;
}
.handleContent {
  width: 100%;
}
.van-col-style {
  font-size: 0.36rem;
  color: #000;
  text-align: left;
  padding-left: 0.2rem;
  margin-top: 0.2rem;
}
.van-cell {
  overflow: inherit;
}
.readonly /deep/.van-field__body {
  background: #ddd;
}
/deep/.van-cell {
  padding: 0.2rem 0.4rem;
}
/deep/.van-field__body {
  border-radius: 2px !important;
  border: 1px solid #ddd;
}
/deep/.van-cell {
  font-size: 0.32rem;
}
/deep/.van-cascader__header {
  height: 1.2rem;
}
/deep/.van-cascader__title {
  flex-grow: 1;
}
/deep/.van-cascader__tabs.van-tabs--line .van-tabs__wrap {
  height: 1rem;
}
.deviceStyle /deep/.van-cell__title {
  width: 4.6em;
}
.scan {
  height: 100%;
  width: 100%;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;

  #bcid {
    width: 100%;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 1rem;
    text-align: center;
    color: #fff;
    background: #ccc;
    font-size: 20px;
    z-index: 999;
    .closeModel {
      position: absolute;
      top: 20px;
      right: 20px;
    }
  }
  footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    bottom: 0;
    height: 1rem;
    font-size: 20px;
    button {
      height: 100%;
      width: 100%;
      border: none;
    }
  }
}
</style>
